﻿/*
  Project:       
  File:          ShopDal.cs
  Description:   
 *               
 *               
 *               
  Author:        Lanny
  Date:          Aug,2014
  version:       1.0
  Modify:
 
                 
 Comments:
 * 1. Need to be tested in multi-network adapter scenarios.
 * 2. Need to be tested in a lagre LAN, lots of PCs do connection task together.
 * 3. Need to add the port check, release ops.   ---Imporant!
 
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using System.Data.SqlClient;
using SQLServerDAL;
using System.Data;

namespace DAL
{
  public class ShopDal : IShopDAL
  {
    string strSql = null;
    public int AddShop(Model.Shops shops)
    {
      strSql = "insert into Shops values(@ShopName,@ShopColor)";
      SqlParameter[] param = new SqlParameter[] { 
                new SqlParameter("@ShopName",shops.ShopName),
                new SqlParameter("@ShopColor",shops.ShopColor)
            };
      return SQLHelper.ExecuteSql(strSql, param);
    }

    public int DeleteShopByID(int Shopid)
    {
      strSql = "delete Shops where ShopID=@ShopID";
      SqlParameter[] paras = new SqlParameter[] { 
                new SqlParameter("@ShopID",Shopid)
            };
      return SQLHelper.ExecuteSql(strSql, paras);
    }

    public int UpdateShop(Model.Shops shops)
    {
      strSql = "update Shops set ShopColor=@ShopColor where ShopName=@ShopName";
      SqlParameter[] paras = new SqlParameter[] { 
              new  SqlParameter("@ShopName",shops.ShopName),
              new SqlParameter("@ShopColor",shops.ShopColor)
            };
      return SQLHelper.ExecuteSql(strSql, paras);
    }

    public System.Data.DataTable GetAllShops()
    {
      strSql = "select * from Shops";
      return SQLHelper.ExecuteDt(strSql);
    }


    public bool isExistShopName(string shopname)
    {
      strSql = "select * from Shops where ShopName=@ShopName";
      SqlParameter[] paras = new SqlParameter[]{
            new SqlParameter("@ShopName",shopname)
          };
      DataTable dt = SQLHelper.ExecuteDt(strSql, paras);
      return dt.Rows.Count == 0 ? false : true;
    }

    public int GetShopId(string shopname)
    {
      strSql = "select * from Shops where ShopName=@ShopName";
      SqlParameter[] paras = new SqlParameter[]{
            new SqlParameter("@ShopName",shopname)
          };
      DataTable dt = SQLHelper.ExecuteDt(strSql, paras);
      return Convert.ToInt32(dt.Rows[0]["ShopID"]);
    }


   
  }
}
